<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>汽车对象</title>
	</head>
	<body>
		<h1>保时捷718 Cayman T,红色,641000元</h1>
		
		<script>
			//js定义对象
			// var car = new Object();//标准写法
			var car = {};//空{}代表js对象,
			var car = {
				//属性k,v键值对结构,语法:key: value,多个属性之间使用逗号分隔
				name: "保时捷719",//js对象写法,不是函数和块,不能加分号;
				note: "这个车很不错!",
				toString: function(){ //初始化时定义一个函数
					return this.name + "," + this.note;//this代表car对象,加上才能访问里面的属性
				}
			}
			//定义属性(动态添加属性)
			// car.name = "保时捷718";
			console.log( car );//直接打印对象,直接观察{name: "保时捷718"}
			car.type = "Cayman T";
			console.log( car );//{name: "保时捷718", type: "Cayman T"}
			car.color = "红色";
			car.price = 641000 + "元";
			
			//动态添加函数
			car.show = function(){
				return this.name+","+this.type+","+this.color+","+this.price;
			}
			
			console.log( car );//{name: "保时捷718", type: "Cayman T", color: "红色", price: "641000元"}
			console.log( car.toString() );//调用函数
			console.log( car.show() );
		</script>
		
	</body>
</html>
